$(function(){
	function createAccount(data)
	{
		var params = {};
		params.data = data;
		return $.ajax({
			url: URL + 'adminapi/createAccount',
			type: 'post',
			data: params,
			dataType: 'json'
		});
	}
	$(document).ready(function(){


		$('#frmCreateAccount').on('valid',function(event){
			var checkboxes = $('#checkboxes :checkbox');
			var not_check = 0;

			$(checkboxes).each(function(i,val){
				
				if(val.checked == false){
					not_check = not_check + 1;
				}else{

				}
			})

			if(not_check == false){
				alert("Please select at least one action");
				return false;	
			}	

			var data = $('#frmCreateAccount').serialize();
			//console.log(data);
			$('.btnCreateAccount').html('Processing <img src="<?=BASE_URI?>img/loading2.gif"/>'); 
			createAccount(data).done(function(result){
				if(result.status == true){
					window.location.reload();	
					
				}else{	
					alert(result.messages);
				}
			});
		});	
		$(document).on('click','.btnCreateAccount',function(){
			$('#frmCreateAccount').submit();
		});
	});
});	
